import 'package:flutter/material.dart';
import 'package:flutter_architecture/src/features/authentication/presentation/account_screen.dart';
import 'package:flutter_architecture/src/features/authentication/presentation/sign_in_controller.dart';
import 'package:flutter_architecture/src/utils/async_value_ui.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';

///@author          Wonderful
///@create          2024-09-14 10:41
class SignInScreen extends ConsumerWidget {
  const SignInScreen({super.key});

  @override
  Widget build(BuildContext context, WidgetRef ref) {
    ref.listen<AsyncValue>(signInControllerProvider,
        (_, state) => state.showSnackBarOnError(context));
    final state = ref.watch(signInControllerProvider);
    return Scaffold(
      appBar: AppBar(title: Text("Sign In")),
      body: Center(
        child: SizedBox(
          width: 200,
          height: 50,
          child: ElevatedButton(
              onPressed: state.isLoading
                  ? null
                  : () => ref
                      .read(signInControllerProvider.notifier)
                      .signInAnonymous(),
              child: state.isLoading
                  ? const CircularProgressIndicator()
                  : const Text("Sign in anonymously")),
        ),
      ),
    );
  }
}
